//
//  NYTeacherTableViewCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/6.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYTeacherTableViewCell.h"
#import "NYTeacherItemModel.h"

@interface NYTeacherTableViewCell ()

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIImageView *backgroundImgView;
@property (nonatomic, strong) UILabel *introduceLabel;
@property (nonatomic, strong) UIImageView *headImgView;
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation NYTeacherTableViewCell
//MARK :Nimbus
- (BOOL)shouldUpdateCellWithObject:(NYTeacherItemModel *)object atIndexPath:(NSIndexPath *)indexPath {
    
    if (![object isKindOfClass:[NYTeacherItemModel class]]) {
        return false;
    }
    self.indexPath = indexPath;
    self.itemModel = object;
    return true;
}
//+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView {
//
//    //    tableView.
//    return 105.f;
//}

- (void)setupView {
    [super setupView];
    
//    self.translatesAutoresizingMaskIntoConstraints = false;

    self.backgroundColor = UIColorMakeWithHex(@"#F3F4F5");
    //布局
    self.accessoryType = UITableViewCellAccessoryNone;
    [self.contentView addSubview:self.bottomView];
    [_bottomView addSubview:self.backgroundImgView];
    [_backgroundImgView addSubview:self.headImgView];
    [_backgroundImgView addSubview:self.nameLabel];

    [_bottomView addSubview:self.introduceLabel];
    
    [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {

//        make.top.mas_equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView).priorityLow();
    }];

    [self.backgroundImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.bottomView);
        make.left.equalTo(self.bottomView);
        make.right.equalTo(self.bottomView);
        make.height.mas_equalTo(134.5f);
    }];
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.backgroundImgView).offset(-20);
        make.left.equalTo(self.backgroundImgView);
        make.right.equalTo(self.backgroundImgView);
        make.height.mas_equalTo(18);
    }];
    
    [self.headImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundImgView).offset(20);
        make.centerX.mas_equalTo(self.backgroundImgView);
        make.width.height.mas_equalTo(66);
    }];
    
    [self.introduceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundImgView.mas_bottom).offset(20);
        make.left.equalTo(self.bottomView).offset(15);
        make.right.equalTo(self.bottomView).offset(-15);
        make.bottom.equalTo(self.bottomView).offset(-15);
    }];
}

#pragma mark - Target Methods

#pragma mark - Public Methods

#pragma mark - Private Method
- (void)updateContent {
    
    self.introduceLabel.text = [NSString stringWithFormat:@"个人简介:%@",self.itemModel.signature];
    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:self.itemModel.thumb]];
    self.nameLabel.text = self.itemModel.user_nicename;
    
//    if (self.indexPath.row == 0) {
//        [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
//
//            make.top.equalTo(self.contentView);
//            make.left.equalTo(self.contentView).offset(15);
//            make.right.equalTo(self.contentView).offset(-15);
//            make.bottom.equalTo(self.contentView).offset(0);
//        }];
//    } else {
//        [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
//
//            make.top.equalTo(self.contentView).offset(15);
//            make.left.equalTo(self.contentView).offset(15);
//            make.right.equalTo(self.contentView).offset(-15);
//            make.bottom.equalTo(self.contentView).offset(0);
//        }];
//    }
}
#pragma mark - External Delegate

#pragma mark - Setter Getter Methods

- (void)setItemModel:(NYTeacherItemModel *)itemModel {
    
    _itemModel = itemModel;
    [self updateContent];
}

- (UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        _bottomView.layer.masksToBounds = true;
        _bottomView.layer.cornerRadius = 11.f;
    }
    return _bottomView;
}
- (UIImageView *)backgroundImgView {
    if (!_backgroundImgView) {
        _backgroundImgView = [[UIImageView alloc] init];
        _backgroundImgView.image = [UIImage yan_jiu_yuan_jiao_shi_jie_shao_bei_jing];
    }
    return _backgroundImgView;
}
- (UILabel *)introduceLabel {
    if (!_introduceLabel) {
        _introduceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _introduceLabel.textColor = UIColorMakeWithHex(@"#666666");
        _introduceLabel.font = UIFontMake(13);
        _introduceLabel.numberOfLines = 0;
    }
    return _introduceLabel;
}
- (UIImageView *)headImgView {
    if (!_headImgView) {
        _headImgView = [[UIImageView alloc] init];
        _headImgView.bounds = CGRectMake(0, 0, 66, 66);
        _headImgView.image = [UIImage qmui_imageWithColor:UIColorMakeWithHex(@"#E5E5E5")];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_headImgView.bounds cornerRadius:33.f];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        maskLayer.frame = _headImgView.bounds;
        maskLayer.path = maskPath.CGPath;
        maskLayer.lineWidth = 2.f;
        maskLayer.strokeColor = [UIColorMakeWithHex(@"#47589D") CGColor];
        _headImgView.layer.mask = maskLayer;
    }
    return _headImgView;
}
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = UIFontMake(17);
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
